package com.aube.base.model;

import com.huyn.baseframework.model.PicItem;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by huyaonan on 15/11/7.
 */
public class TimeLineData implements Serializable {

    public String videoid="";
    public String videono="";
    public String starttime="";
    public String endtime="";
    public String title="";
    public List<TimeLinePiece> timeline;

    //新增背景图片
    public PicItem bgpic;

    public String themeColor="";//qa选中的颜色, #ff0000

    public String getBgUrl() {
        return bgpic == null ? "" : bgpic.picurl;
    }

    public int size() {
        if(timeline == null)
            return 0;
        return timeline.size();
    }

    public TimeLinePiece getItem(int index) {
        if(index < 0 || index >= size())
            return null;
        return timeline.get(index);
    }

    public List<TimeLinePiece> formatList() {
        if(timeline == null)
            return null;
        List<TimeLinePiece> result = new ArrayList<>();
        for(TimeLinePiece item : timeline)
            result.addAll(item.format());

        Collections.sort(result, new Comparator<TimeLinePiece>() {
            @Override
            public int compare(TimeLinePiece lhs, TimeLinePiece rhs) {
                if(lhs.startSeconds < rhs.startSeconds)
                    return -1;
                else if(lhs.startSeconds > rhs.startSeconds)
                    return 1;
                else
                    return 0;
            }
        });

        return result;
    }

}
